import request from "@/utils/request"
import type { CommentItem } from "@/types/web/community"

/** 评论发表数据 */
export interface CommentData {
  nickname: string
  content: string
  address?: string
  time?: string
}

/** 获取文章评论列表（完全公开） */
export function getArticleCommentsAPI(articleId: string, page: number = 1, pageSize: number = 10) {
  return request<{
    data: CommentItem[]
    total: number
  }>({
    url: `/web/public/community/${articleId}/comments`,
    method: "get",
    params: {
      page,
      pageSize
    }
  })
}

/** 获取文章评论列表（兼容接口） */
export function getArticleCommentsListAPI(articleId: string, page: number = 1, pageSize: number = 10) {
  return request<{
    data: CommentItem[]
    total: number
  }>({
    url: `/web/public/community/comment/list/${articleId}`,
    method: "get",
    params: {
      page,
      pageSize
    }
  })
}

/** 发表文章评论（路径参数） */
export function publishArticleCommentAPI(articleId: string, data: CommentData) {
  return request({
    url: `/web/public/community/${articleId}/comment`,
    method: "post",
    data
  })
}

/** 发表文章评论（请求体参数） */
export function publishCommentAPI(data: CommentData & { postId: string }) {
  return request({
    url: `/web/public/community/comment`,
    method: "post",
    data
  })
}

/** 发表文章评论（兼容接口 - 使用articleID字段） */
export function publishCommentCompatAPI(data: CommentData & { articleID: string }) {
  return request({
    url: `/web/public/community/comment`,
    method: "post",
    data
  })
}
